home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Harvest C / MPW Int & Lib / Interfaces / MIDI.h < prev    next >
Text File  |  1991-04-17  |  11KB  |  276 lines

  1. /************************************************************
  2.  
  3. Created: Tuesday, January 8, 1991 at 10:53 AM
  4.     MIDI.h
  5.     C Interface to the Macintosh Libraries
  6.  
  7.  
  8.             Copyright © 1988-1990, Apple Computer, Inc.
  9.             All Rights Reserved
  10.  
  11. ************************************************************/
  12.  
  13.  
  14. #ifndef __MIDI__
  15. #define __MIDI__
  16.  
  17. #ifndef __TYPES__
  18. #include <Types.h>
  19. #endif
  20.  
  21.  
  22. enum {
  23.  
  24.  
  25. #define midiToolNum 4                   /*tool number of MIDI Manager for SndDispVersion call*/
  26.  
  27.     midiMaxNameLen = 31,                /*maximum number of characters in port and client names*/
  28.  
  29. /* Time formats */
  30.     midiFormatMSec = 0,                 /*milliseconds*/
  31.     midiFormatBeats = 1,                /*beats*/
  32.     midiFormat24fpsBit = 2,             /*24 frames/sec.*/
  33.     midiFormat25fpsBit = 3,             /*25 frames/sec.*/
  34.     midiFormat30fpsDBit = 4,            /*30 frames/sec. drop-frame*/
  35.     midiFormat30fpsBit = 5,             /*30 frames/sec.*/
  36.     midiFormat24fpsQF = 6,              /*24 frames/sec. longInt format */
  37.     midiFormat25fpsQF = 7,              /*25 frames/sec. longInt format */
  38.     midiFormat30fpsDQF = 8,             /*30 frames/sec. drop-frame longInt format */
  39.     midiFormat30fpsQF = 9,              /*30 frames/sec. longInt format */
  40.     midiInternalSync = 0,               /*internal sync*/
  41.     midiExternalSync = 1,               /*external sync*/
  42.  
  43. /* Port types*/
  44.     midiPortTypeTime = 0,               /*time port*/
  45.     midiPortTypeInput = 1,              /*input port*/
  46.     midiPortTypeOutput = 2,             /*output port*/
  47.     midiPortTypeTimeInv = 3,            /*invisible time port*/
  48.  
  49. /* OffsetTimes  */
  50.     midiGetEverything = 0x7FFFFFFF,     /*get all packets, regardless of time stamps*/
  51.     midiGetNothing = 0x80000000,        /*get no packets, regardless of time stamps*/
  52.     midiGetCurrent = 0x00000000         /*get current packets only*/
  53. };
  54. enum {
  55.  
  56. /*    MIDI data and messages are passed in MIDIPacket records (see below).
  57.     The first byte of every MIDIPacket contains a set of flags
  58.    
  59.     bits 0-1    00 = new MIDIPacket, not continued
  60.                      01 = begining of continued MIDIPacket
  61.                      10 = end of continued MIDIPacket
  62.                     11 = continuation
  63.     bits 2-3     reserved
  64.   
  65.     bits 4-6      000 = packet contains MIDI data
  66.    
  67.                      001 = packet contains MIDI Manager message
  68.    
  69.     bit 7              0 = MIDIPacket has valid stamp
  70.                         1 = stamp with current clock */
  71.     midiContMask = 0x03,
  72.     midiNoCont = 0x00,
  73.     midiStartCont = 0x01,
  74.     midiMidCont = 0x03,
  75.     midiEndCont = 0x02,
  76.     midiTypeMask = 0x70,
  77.     midiMsgType = 0x00,
  78.     midiMgrType = 0x10,
  79.     midiTimeStampMask = 0x80,
  80.     midiTimeStampCurrent = 0x80,
  81.     midiTimeStampValid = 0x00,
  82.  
  83. /*    MIDI Manager MIDIPacket command words (the first word in the data field
  84.     for midiMgrType messages) */
  85.     midiOverflowErr = 0x0001,
  86.     midiSCCErr = 0x0002,
  87.     midiPacketErr = 0x0003,
  88.     midiMaxErr = 0x00FF,                /*all command words less than this value  are error indicators*/
  89.  
  90. /* Valid results to be returned by readHooks */
  91.     midiKeepPacket = 0,
  92.     midiMorePacket = 1,
  93.     midiNoMorePacket = 2,
  94.  
  95. /* Errors: */
  96.     midiNoClientErr = -250,             /*no client with that ID found*/
  97.     midiNoPortErr = -251                /*no port with that ID found*/
  98. };
  99. enum {
  100.     midiTooManyPortsErr = -252,         /*too many ports already installed in the system*/
  101.     midiTooManyConsErr = -253,          /*too many connections made*/
  102.     midiVConnectErr = -254,             /*pending virtual connection created*/
  103.     midiVConnectMade = -255,            /*pending virtual connection resolved*/
  104.     midiVConnectRmvd = -256,            /*pending virtual connection removed*/
  105.     midiNoConErr = -257,                /*no connection exists between specified ports*/
  106.     midiWriteErr = -258,                /*MIDIWritePacket couldn't write to all connected ports*/
  107.     midiNameLenErr = -259,              /*name supplied is longer than 31 characters*/
  108.     midiDupIDErr = -260,                /*duplicate client ID*/
  109.     midiInvalidCmdErr = -261,           /*command not supported for port type*/
  110.  
  111. /*     Driver calls: */
  112.     midiOpenDriver = 1,
  113.     midiCloseDriver = 2
  114. };
  115.  
  116. struct MIDIPacket {
  117.     unsigned char flags;
  118.     unsigned char len;
  119.     long tStamp;
  120.     unsigned char data[249];
  121. };
  122.  
  123. typedef struct MIDIPacket MIDIPacket;
  124. typedef MIDIPacket *MIDIPacketPtr;
  125.  
  126. struct MIDIClkInfo {
  127.     short sync;                         /*synchronization external/internal*/
  128.     long curTime;                       /*current value of port's clock*/
  129.     short format;                       /*time code format*/
  130. };
  131.  
  132. typedef struct MIDIClkInfo MIDIClkInfo;
  133.  
  134. struct MIDIIDRec {
  135.     OSType clientID;
  136.     OSType portID;
  137. };
  138.  
  139. typedef struct MIDIIDRec MIDIIDRec;
  140.  
  141. struct MIDIPortInfo {
  142.     short portType;                     /*type of port*/
  143.     MIDIIDRec timeBase;                 /*MIDIIDRec for time base*/
  144.     short numConnects;                  /*number of connections*/
  145.     MIDIIDRec cList[1];                 /*ARRAY [1..numConnects] of MIDIIDRec*/
  146. };
  147.  
  148. typedef struct MIDIPortInfo MIDIPortInfo;
  149. typedef MIDIPortInfo *MIDIPortInfoPtr, **MIDIPortInfoHdl;
  150.  
  151. struct MIDIPortParams {
  152.     OSType portID;                      /*ID of port, unique within client*/
  153.     short portType;                     /*Type of port - input, output, time, etc.*/
  154.     short timeBase;                     /*refnum of time base, 0 if none*/
  155.     long offsetTime;                    /*offset for current time stamps*/
  156.     Ptr readHook;                       /*routine to call when input data is valid*/
  157.     long refCon;                        /*refcon for port (for client use)*/
  158.     MIDIClkInfo initClock;              /*initial settings for a time base*/
  159.     Str255 name;                        /*name of the port, This is a real live string, not a ptr.*/
  160. };
  161.  
  162. typedef struct MIDIPortParams MIDIPortParams;
  163. typedef MIDIPortParams *MIDIPortParamsPtr;
  164.  
  165. struct MIDIIDList {
  166.     short numIDs;
  167.     OSType list[1];
  168. };
  169.  
  170. typedef struct MIDIIDList MIDIIDList;
  171. typedef MIDIIDList *MIDIIDListPtr, **MIDIIDListHdl;
  172.  
  173.  
  174. #ifdef __cplusplus
  175. extern "C" {
  176. #endif
  177.  
  178. /* 
  179.     
  180.          Prototype Declarations for readHook and timeProc
  181.         
  182.          extern pascal short myReadHook(MIDIPacketPtr myPacket, long myRefCon);
  183.          extern pascal void myTimeProc(long curTime, long myRefCon);
  184.         
  185.          MIDI Manager Routines
  186. */
  187.  
  188. pascal long SndDispVersion(short toolnum); 
  189. pascal OSErr MIDISignIn(OSType clientID,long refCon,Handle icon,ConstStr255Param name)
  190.     = {0x203C,0x0004,midiToolNum,0xA800}; 
  191. pascal void MIDISignOut(OSType clientID)
  192.     = {0x203C,0x0008,midiToolNum,0xA800}; 
  193. pascal MIDIIDListHdl MIDIGetClients(void)
  194.     = {0x203C,0x000C,midiToolNum,0xA800}; 
  195. pascal void MIDIGetClientName(OSType clientID,Str255 name)
  196.     = {0x203C,0x0010,midiToolNum,0xA800}; 
  197. pascal void MIDISetClientName(OSType clientID,ConstStr255Param name)
  198.     = {0x203C,0x0014,midiToolNum,0xA800}; 
  199. pascal MIDIIDListHdl MIDIGetPorts(OSType clientID)
  200.     = {0x203C,0x0018,midiToolNum,0xA800}; 
  201. pascal OSErr MIDIAddPort(OSType clientID,short BufSize,short *refnum,MIDIPortParamsPtr init)
  202.     = {0x203C,0x001C,midiToolNum,0xA800}; 
  203. pascal MIDIPortInfoHdl MIDIGetPortInfo(OSType clientID,OSType portID)
  204.     = {0x203C,0x0020,midiToolNum,0xA800}; 
  205. pascal OSErr MIDIConnectData(OSType srcClID,OSType srcPortID,OSType dstClID,
  206.     OSType dstPortID)
  207.     = {0x203C,0x0024,midiToolNum,0xA800}; 
  208. pascal OSErr MIDIUnConnectData(OSType srcClID,OSType srcPortID,OSType dstClID,
  209.     OSType dstPortID)
  210.     = {0x203C,0x0028,midiToolNum,0xA800}; 
  211. pascal OSErr MIDIConnectTime(OSType srcClID,OSType srcPortID,OSType dstClID,
  212.     OSType dstPortID)
  213.     = {0x203C,0x002C,midiToolNum,0xA800}; 
  214. pascal OSErr MIDIUnConnectTime(OSType srcClID,OSType srcPortID,OSType dstClID,
  215.     OSType dstPortID)
  216.     = {0x203C,0x0030,midiToolNum,0xA800}; 
  217. pascal void MIDIFlush(short refnum)
  218.     = {0x203C,0x0034,midiToolNum,0xA800}; 
  219. pascal ProcPtr MIDIGetReadHook(short refnum)
  220.     = {0x203C,0x0038,midiToolNum,0xA800}; 
  221. pascal void MIDISetReadHook(short refnum,ProcPtr hook)
  222.     = {0x203C,0x003C,midiToolNum,0xA800}; 
  223. pascal void MIDIGetPortName(OSType clientID,OSType portID,Str255 name)
  224.     = {0x203C,0x0040,midiToolNum,0xA800}; 
  225. pascal void MIDISetPortName(OSType clientID,OSType portID,ConstStr255Param name)
  226.     = {0x203C,0x0044,midiToolNum,0xA800}; 
  227. pascal void MIDIWakeUp(short refnum,long time,long period,ProcPtr timeProc)
  228.     = {0x203C,0x0048,midiToolNum,0xA800}; 
  229. pascal void MIDIRemovePort(short refnum)
  230.     = {0x203C,0x004C,midiToolNum,0xA800}; 
  231. pascal short MIDIGetSync(short refnum)
  232.     = {0x203C,0x0050,midiToolNum,0xA800}; 
  233. pascal void MIDISetSync(short refnum,short sync)
  234.     = {0x203C,0x0054,midiToolNum,0xA800}; 
  235. pascal long MIDIGetCurTime(short refnum)
  236.     = {0x203C,0x0058,midiToolNum,0xA800}; 
  237. pascal void MIDISetCurTime(short refnum,long time)
  238.     = {0x203C,0x005C,midiToolNum,0xA800}; 
  239. pascal void MIDIStartTime(short refnum)
  240.     = {0x203C,0x0060,midiToolNum,0xA800}; 
  241. pascal void MIDIStopTime(short refnum)
  242.     = {0x203C,0x0064,midiToolNum,0xA800}; 
  243. pascal void MIDIPoll(short refnum,long offsetTime)
  244.     = {0x203C,0x0068,midiToolNum,0xA800}; 
  245. pascal OSErr MIDIWritePacket(short refnum,MIDIPacketPtr packet)
  246.     = {0x203C,0x006C,midiToolNum,0xA800}; 
  247. pascal Boolean MIDIWorldChanged(OSType clientID)
  248.     = {0x203C,0x0070,midiToolNum,0xA800}; 
  249. pascal long MIDIGetOffsetTime(short refnum)
  250.     = {0x203C,0x0074,midiToolNum,0xA800}; 
  251. pascal void MIDISetOffsetTime(short refnum,long offsetTime)
  252.     = {0x203C,0x0078,midiToolNum,0xA800}; 
  253. pascal long MIDIConvertTime(short srcFormat,short dstFormat,long time)
  254.     = {0x203C,0x007C,midiToolNum,0xA800}; 
  255. pascal long MIDIGetRefCon(short refnum)
  256.     = {0x203C,0x0080,midiToolNum,0xA800}; 
  257. pascal void MIDISetRefCon(short refnum,long refCon)
  258.     = {0x203C,0x0084,midiToolNum,0xA800}; 
  259. pascal long MIDIGetClRefCon(OSType clientID)
  260.     = {0x203C,0x0088,midiToolNum,0xA800}; 
  261. pascal void MIDISetClRefCon(OSType clientID,long refCon)
  262.     = {0x203C,0x008C,midiToolNum,0xA800}; 
  263. pascal short MIDIGetTCFormat(short refnum)
  264.     = {0x203C,0x0090,midiToolNum,0xA800}; 
  265. pascal void MIDISetTCFormat(short refnum,short format)
  266.     = {0x203C,0x0094,midiToolNum,0xA800}; 
  267. pascal void MIDISetRunRate(short refnum,short rate,long time)
  268.     = {0x203C,0x0098,midiToolNum,0xA800}; 
  269. pascal Handle MIDIGetClientIcon(OSType clientID)
  270.     = {0x203C,0x009C,midiToolNum,0xA800}; 
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274.  
  275. #endif
  276.